/* -----------------------------------------------------------------------
 * Don't forget to include the following lines in your makefile:
 *
 * testFileName: testFileName.c dominion.o rngs.o
 *      gcc -o testFileName -g  testFileName.c dominion.o rngs.o $(CFLAGS)
 * -----------------------------------------------------------------------
 *
 *  unittest3 tests the updateCoins() function
 */

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
//#include "rngs.h"

// set NOISY_TEST to 0 to remove printfs from output
#define NOISY_TEST 1

int main() {
    int i,j,c;
    int seed = 1000;
    int numPlayer = 2;
    int bonus = 0;
    int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
    struct gameState G;

    int game1 = initializeGame(numPlayer, k, seed, &G);
    assert(game1 == 0);

#if (NOISY_TEST == 1)
        printf("Game initialized!!\n");
        printf("Test initial state...\n");
#endif
    for (i = 0; i < numPlayer; i++){
        c = 0;
        for(j = 0; j < G.handCount[i]; j++){
            if(G.hand[i][j] == copper){
                c++;
            }
            printf("Found %d coppers\n",c);
        }
        updateCoins(i,&G,bonus);
        printf("Coins = %d\n",G.coins);
        assert(G.coins == c);
    }
#if (NOISY_TEST == 1)
        printf("Test adding coins...\n");
#endif
    for (i = 0; i < numPlayer; i++){
        c = 0;
        for(j = 0; j < i+2; j++){
            G.hand[i][G.handCount[i]] = silver;
            G.handCount[i]++;
        }
        for(j = 0; j < G.handCount[i]; j++){
            if(G.hand[i][j] == copper){
                c++;
            }
            else if(G.hand[i][j] == silver){
                c += 2;
            }
            else if(G.hand[i][j] == gold){
                c += 3;
            }
            //printf("Found %d $$\n",c);
        }
        updateCoins(i,&G,bonus);
        //printf("Coins = %d\n",G.coins);
        assert(G.coins == c);
    }
#if (NOISY_TEST == 1)
        printf("Test adding bonus...\n");
#endif
    for(i = 0; i < numPlayer; i++){
        bonus = 0;
        updateCoins(i,&G,bonus);
        c = G.coins;
        if(i % 2 == 0){
            bonus = i+5;
            c += bonus;
        }
        updateCoins(i,&G,bonus);
        assert(G.coins == c);
    }
#if (NOISY_TEST == 1)
        printf("Test clearing coins...\n");
#endif
    for(i = 0; i < numPlayer; i++){
        bonus = 0;
        for(j = 0; j < G.handCount[i]; j++){
            if(G.hand[i][j] == copper || G.hand[i][j] == silver || G.hand[i][j] == gold)
                G.hand[i][j] = estate;
        }
        updateCoins(i,&G,bonus);
        c = 0;
        assert(G.coins == c);
    }

#if (NOISY_TEST == 1)
        printf("Success!!\n");
#endif

    return 0;
}
